package view;

import javax.microedition.lcdui.Command;
import javax.microedition.lcdui.Displayable;
import javax.microedition.lcdui.Form;
import javax.microedition.lcdui.Item;
import javax.microedition.lcdui.StringItem;

public class View1 extends MVCComponent {
	
	private Command cmd_next = new Command("Next", Command.OK, 1);

	private Form form;
	private StringItem sTime;
	
	private int numViews;

	protected void createView() {
		form = new Form("Example");
		form.addCommand(cmd_next);
		
		sTime = new StringItem("Viewed this:",  numViews+" time(s)", Item.PLAIN);
		form.append(sTime);
	}

	public Displayable getScreen() {
		return form;
	}

	protected void initModel() {
		numViews = 1;
	}

	protected void updateView() {
		numViews++;
		sTime.setText(numViews+" time(s)");
	}
	
	public void commandAction(Command cmd, Displayable display) {
		if(cmd == cmd_next) {
			View2 view2 = new View2();
			view2.setCallerView(this);
			view2.showScreen();
		}
	}

}